package com.lanou3g.ptp.grade.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.lanou3g.ptp.entity.Grade;
import com.lanou3g.ptp.entity.TaskRole;
import com.lanou3g.ptp.grade.mapper.GradeMapper;
import com.lanou3g.ptp.grade.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {
    @Autowired
    private GradeMapper gradeMapper;

    //  添加一个grade
    @Override
    public void insertGrade(Grade grade) {
        grade.setCreateTime(new Date());
        grade.setUpdateTime(new Date());
        gradeMapper.insertGrade(grade);
    }

    //  更改grade信息
    @Override
    public void updateGrade(Grade grade) {
        grade.setUpdateTime(new Date());
        gradeMapper.updateGrade(grade);
    }

    //  查找全部grade
    @Override
    public List<Grade> findAll() {
        List<Grade> gradeList = gradeMapper.findAll();
        return gradeList;
    }

    //  根据id查找grade
    @Override
    public Grade findById(Long id) {
        Grade grade = gradeMapper.findById(id);
        return grade;
    }

    //  通过id删除grade
    @Override
    public void deleteById(Long id) {
        gradeMapper.deleteById(id);
    }

    //  通过id删除grade
    @Override
    public void deleteGradeRoleById(Long gradeId) {
        gradeMapper.deleteGradeRoleById(gradeId);
    }

    //  通过ids批量查询
    @Override
    public void deleteByIds(Integer[] ids) {
        gradeMapper.deleteByIds(ids);
    }

    //    通过taskId查询所有参与这次打分的老师
    @Override
    public List<Long> findByTaskId(Long taskId) {
        List<Long> roleIds = new ArrayList<>();
        List<TaskRole> taskRoles = gradeMapper.findByTaskId(taskId);
        for (TaskRole taskRole : taskRoles) {
            roleIds.add(taskRole.getId());
        }
        return roleIds;
    }

}
